package com.czm.art_light.patterns.strategy.impl;

import com.czm.art_light.constant.CommonConsts;
import com.czm.art_light.entity.ArtUserActions;
import com.czm.art_light.manager.mq.producer.AmqpMsgProducer;
import com.czm.art_light.param.request.ArtWorkESReqDto;
import com.czm.art_light.param.request.UserActionReqDto;
import com.czm.art_light.patterns.strategy.UserActionStrategy;
import com.czm.art_light.service.ArtStatisticsService;
import com.czm.art_light.service.ArtUserActionsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 取消喜欢行为的策略实现类
 */
@Component
public class UnlikeStrategy implements UserActionStrategy {
    @Autowired
    private ArtUserActionsService artUserActionsService;

    @Autowired
    private ArtStatisticsService artStatisticsService;

    @Autowired
    private AmqpMsgProducer amqpMsgProducer;

/*    @Override
    public void recordUserActions(UserActionReqDto userActionReqDto) {
//        System.out.println("记录用户取消喜欢行为...");
        // 将用户取消喜欢该艺术画作品的行为记录到数据库中
        artUserActionsService.recordUserActions(ArtUserActions.builder()
                //用户id
                .userId(userActionReqDto.getUserId())
                //作品id
                .workId(userActionReqDto.getWorkId())
                //操作类型：点击
                .actionType(userActionReqDto.getActionType().getValue())
                //操作时间(当前时间)
                .actionTime(LocalDateTime.now())
                .build());
    }*/

    @Override
    public void updateStatisticsData(UserActionReqDto userActionReqDto) {
//        System.out.println("更新取消喜欢量统计数据...");
        //喜欢量-1
        artStatisticsService.decrementLikeCount(userActionReqDto.getWorkId());
    }

/*    @Override
    public void pushMessage(UserActionReqDto userActionReqDto) {
//        System.out.println("推送取消喜欢行为相关消息...");
        // 发送消息，更新ES中艺术作品的统计信息
        amqpMsgProducer.sendArtworkChangeMsg(new ArtWorkESReqDto(userActionReqDto.getWorkId(),false));
    }*/

    @Override
    public String getAction() {
        return CommonConsts.ActionType.DISLIKE.getValue();
    }
}